package com.lfx.half;

/**
 * @author 李逢喜
 * create 2021/7/15
 */
public class HalfDemo {


    public static  int binarySearch(int[] nums, int t){

        int low=0;
        int high=nums.length;
        int mid=0;
        int num=-1;
        int count=1;
        while (low<=high){
            mid=(low+high)/2;

            int num1 = nums[mid];
            if(num1>t){
                high= mid-1;
            }else if(num1<t){
                low=mid+1;
            }else
               return num1;
            System.out.println("循环次数"+count);

            count++;

        }
        return num;
    }

    public static void main(String[] args) {
        int[] nums = {3, 12, 24, 31, 46, 48, 52, 66, 69, 79, 82};
        System.out.println(binarySearch(nums,11));
    }
}
